<?php


abstract class BaseUserNotice extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $title;


	
	protected $content;


	
	protected $created_datetime;


	
	protected $to_user = 0;


	
	protected $notice_type = 'inform';


	
	protected $notice_order = 0;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getTitle()
	{

		return $this->title;
	}

	
	public function getContent()
	{

		return $this->content;
	}

	
	public function getCreatedDatetime($format = 'Y-m-d H:i:s')
	{

		if ($this->created_datetime === null || $this->created_datetime === '') {
			return null;
		} elseif (!is_int($this->created_datetime)) {
						$ts = strtotime($this->created_datetime);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_datetime] as date/time value: " . var_export($this->created_datetime, true));
			}
		} else {
			$ts = $this->created_datetime;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getToUser()
	{

		return $this->to_user;
	}

	
	public function getNoticeType()
	{

		return $this->notice_type;
	}

	
	public function getNoticeOrder()
	{

		return $this->notice_order;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = UserNoticePeer::ID;
		}

	} 
	
	public function setTitle($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->title !== $v) {
			$this->title = $v;
			$this->modifiedColumns[] = UserNoticePeer::TITLE;
		}

	} 
	
	public function setContent($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->content !== $v) {
			$this->content = $v;
			$this->modifiedColumns[] = UserNoticePeer::CONTENT;
		}

	} 
	
	public function setCreatedDatetime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_datetime] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_datetime !== $ts) {
			$this->created_datetime = $ts;
			$this->modifiedColumns[] = UserNoticePeer::CREATED_DATETIME;
		}

	} 
	
	public function setToUser($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->to_user !== $v || $v === 0) {
			$this->to_user = $v;
			$this->modifiedColumns[] = UserNoticePeer::TO_USER;
		}

	} 
	
	public function setNoticeType($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->notice_type !== $v || $v === 'inform') {
			$this->notice_type = $v;
			$this->modifiedColumns[] = UserNoticePeer::NOTICE_TYPE;
		}

	} 
	
	public function setNoticeOrder($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->notice_order !== $v || $v === 0) {
			$this->notice_order = $v;
			$this->modifiedColumns[] = UserNoticePeer::NOTICE_ORDER;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->title = $rs->getString($startcol + 1);

			$this->content = $rs->getString($startcol + 2);

			$this->created_datetime = $rs->getTimestamp($startcol + 3, null);

			$this->to_user = $rs->getInt($startcol + 4);

			$this->notice_type = $rs->getString($startcol + 5);

			$this->notice_order = $rs->getInt($startcol + 6);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating UserNotice object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UserNoticePeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			UserNoticePeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UserNoticePeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = UserNoticePeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += UserNoticePeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = UserNoticePeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = UserNoticePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getTitle();
				break;
			case 2:
				return $this->getContent();
				break;
			case 3:
				return $this->getCreatedDatetime();
				break;
			case 4:
				return $this->getToUser();
				break;
			case 5:
				return $this->getNoticeType();
				break;
			case 6:
				return $this->getNoticeOrder();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = UserNoticePeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getTitle(),
			$keys[2] => $this->getContent(),
			$keys[3] => $this->getCreatedDatetime(),
			$keys[4] => $this->getToUser(),
			$keys[5] => $this->getNoticeType(),
			$keys[6] => $this->getNoticeOrder(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = UserNoticePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setTitle($value);
				break;
			case 2:
				$this->setContent($value);
				break;
			case 3:
				$this->setCreatedDatetime($value);
				break;
			case 4:
				$this->setToUser($value);
				break;
			case 5:
				$this->setNoticeType($value);
				break;
			case 6:
				$this->setNoticeOrder($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = UserNoticePeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setTitle($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setContent($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCreatedDatetime($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setToUser($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setNoticeType($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setNoticeOrder($arr[$keys[6]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(UserNoticePeer::DATABASE_NAME);

		if ($this->isColumnModified(UserNoticePeer::ID)) $criteria->add(UserNoticePeer::ID, $this->id);
		if ($this->isColumnModified(UserNoticePeer::TITLE)) $criteria->add(UserNoticePeer::TITLE, $this->title);
		if ($this->isColumnModified(UserNoticePeer::CONTENT)) $criteria->add(UserNoticePeer::CONTENT, $this->content);
		if ($this->isColumnModified(UserNoticePeer::CREATED_DATETIME)) $criteria->add(UserNoticePeer::CREATED_DATETIME, $this->created_datetime);
		if ($this->isColumnModified(UserNoticePeer::TO_USER)) $criteria->add(UserNoticePeer::TO_USER, $this->to_user);
		if ($this->isColumnModified(UserNoticePeer::NOTICE_TYPE)) $criteria->add(UserNoticePeer::NOTICE_TYPE, $this->notice_type);
		if ($this->isColumnModified(UserNoticePeer::NOTICE_ORDER)) $criteria->add(UserNoticePeer::NOTICE_ORDER, $this->notice_order);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(UserNoticePeer::DATABASE_NAME);

		$criteria->add(UserNoticePeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setTitle($this->title);

		$copyObj->setContent($this->content);

		$copyObj->setCreatedDatetime($this->created_datetime);

		$copyObj->setToUser($this->to_user);

		$copyObj->setNoticeType($this->notice_type);

		$copyObj->setNoticeOrder($this->notice_order);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new UserNoticePeer();
		}
		return self::$peer;
	}

} 